<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4692：Beautiful Spacing</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Beautiful Spacing</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">Beautiful Spacing</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                Beautiful Spacing                </h1>
                <p>时间限制：15s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>
<div>文章是一些单词组成的序列，单词由字母组成。你的任务是将一篇文章的单词填充到一个网格中，其中网格包含W</div>
<div>列和足够多的行。为了布局之美，以下限制都需要满足。</div>
<div>1.文章中的文字需要按照原有的顺序放置。下图表示了将4个单词的文章&ldquo;This is a pen&rdquo;放入11列的网格正确和</div>
<div>错误的例子。</div>
<div><img src="../file/4692_0.png" width="616" height="127" alt="" /></div>
<div>2.在同一行的两个相邻单词之间要有至少一个空格。有时你会需要放置多于一个空格来满足其他限制。</div>
<div><img src="../file/4692_1.png" width="573" height="176" alt="" /></div>
<div>3.一个单词必须被放置到连续的列中，一个格子只含一个字符。你不能将通过增加空格或换行将一个单词分成多个</div>
<div>部分。</div>
<div><img src="../file/4692_2.png" width="554" height="120" alt="" /></div>
<div>4.文章必须占据边缘两列的格子，即每行的第一个单词必须占用第一个格子，且除了最后一行之外的每行的最后一</div>
<div>个单词必须占用最后一个格子。</div>
<div><img src="../file/4692_3.png" width="656" height="125" alt="" /></div>
<div>文章拥有最美的布局时，每一行都不会有过多的连续空格，在下图的例子里只有最多2个连续空格，而第一个例子</div>
<div>里有3个连续空格，所以下图的例子比第一个例子美观。给定文章的信息和列数，请你找到一个最优的布局，使得</div>
<div>最长连续空格尽量短。</div>
<div><img src="../file/4692_4.png" width="508" height="167" alt="" /></div>
<div></div>
</div>
<p></p></p><hr/><h3>输入格式</h3><p><div>输入包含多组测试数据。每组数据第一行包含两个正整数W和N，其中W表示列数(3&le;W&le;80000)，N表示文章的单词数量(2&le;N&le;50000)。</div>
<div>第二行包含N个正整数，按照文章中单词的顺序给出每个单词的字符数量，</div>
<div>对于第i个单词的字符数量xi，有1&le;x_i&le;(W-1)/2，从而这也使得答案一定存在。</div>
<div>输入以两个零作为结束。</div>
<p></p></p><hr/><h3>输出格式</h3><p><p>对于每组数据，输出一个正整数表示最长连续空格长度的最小值。</p>
<p></p></p><hr/><h3>样例输入</h3><pre>11 4
4 2 1 3
5 7
1 1 1 2 2 1 2
11 7
3 1 3 1 3 3 4
100 3
30 30 39
30 3
2 5 3
0 0</pre><hr/><h3>样例输出</h3><pre>2
1
2
40
1
</pre><hr/><h3>提示</h3><p>没有写明提示</p><hr/><h3>题目来源</h3><p>鸣谢Tangjz提供试题</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4692" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4692" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>